gtk-demo: Tweak the animated paintable
authorMatthias Clasen <mclasen@redhat.com>
Sat, 12 Sep 2020 01:08:36 +0000 (21:08 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 12 Sep 2020 01:08:36 +0000 (21:08 -0400)
Make it possible to have no background in
the animated paintable. This will be used
in a future demo.

Update all users.

demos/gtk-demo/paintable.c
demos/gtk-demo/paintable.h
demos/gtk-demo/paintable_animated.c
demos/gtk-demo/paintable_mediastream.c
demos/gtk-demo/sliding_puzzle.c
demos/gtk-demo/textview.c

index 3b3da1e0bc3f527a0da146228d7aad2b70ff1b77..933e7abd482af725c9e677547129de6a46101cf0 100644 (file)
@@ -48,15 +48,17 @@ void
 gtk_nuclear_snapshot (GtkSnapshot *snapshot,
                       double       width,
                       double       height,
-                      double       rotation)
+                      double       rotation,
+                      gboolean     draw_background)
 {
 #define RADIUS 0.3
   cairo_t *cr;
   double size;
 
-  gtk_snapshot_append_color (snapshot,
-                             &(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 },
-                             &GRAPHENE_RECT_INIT (0, 0, width, height));
+  if (draw_background)
+    gtk_snapshot_append_color (snapshot,
+                               &(GdkRGBA) { 0.9, 0.75, 0.15, 1.0 },
+                               &GRAPHENE_RECT_INIT (0, 0, width, height));
 
   size = MIN (width, height);
   cr = gtk_snapshot_append_cairo (snapshot,
@@ -93,7 +95,8 @@ gtk_nuclear_icon_snapshot (GdkPaintable *paintable,
 
   gtk_nuclear_snapshot (snapshot,
                         width, height,
-                        nuclear->rotation);
+                        nuclear->rotation,
+                        TRUE);
 }
 
 static GdkPaintableFlags
index 33bc4dbc8b24b5dad668e0213c2a9ee765397925..a89713f9b1a108aa43086675c2bd4719a43f342d 100644 (file)
@@ -6,10 +6,11 @@
 void            gtk_nuclear_snapshot           (GtkSnapshot     *snapshot,
                                                 double           width,
                                                 double           height,
-                                                double           rotation);
+                                                double           rotation,
+                                                gboolean         draw_background);
 
 GdkPaintable *  gtk_nuclear_icon_new            (double          rotation);
-GdkPaintable *  gtk_nuclear_animation_new       (void);
+GdkPaintable *  gtk_nuclear_animation_new       (gboolean        draw_background);
 GtkMediaStream *gtk_nuclear_media_stream_new    (void);
 
 #endif /* __PAINTABLE_H__ */
index 17b1372d98d7ba601078fc45f852857f506b1f87..93a51d492cd27bfc6f62ea9370ba0fdf7c966c72 100644 (file)
@@ -33,6 +33,8 @@ struct _GtkNuclearAnimation
 {
   GObject parent_instance;
 
+  gboolean draw_background;
+
   /* This variable stores the progress of our animation.
    * We just count upwards until we hit MAX_PROGRESS and
    * then start from scratch.
@@ -64,7 +66,8 @@ gtk_nuclear_animation_snapshot (GdkPaintable *paintable,
   /* We call the function from the previous example here. */
   gtk_nuclear_snapshot (snapshot,
                         width, height,
-                        2 * G_PI * nuclear->progress / MAX_PROGRESS);
+                        2 * G_PI * nuclear->progress / MAX_PROGRESS,
+                        nuclear->draw_background);
 }
 
 static GdkPaintable *
@@ -175,9 +178,15 @@ gtk_nuclear_animation_init (GtkNuclearAnimation *nuclear)
 
 /* And finally, we add the simple constructor we declared in the header. */
 GdkPaintable *
-gtk_nuclear_animation_new (void)
+gtk_nuclear_animation_new (gboolean draw_background)
 {
-  return g_object_new (GTK_TYPE_NUCLEAR_ANIMATION, NULL);
+  GtkNuclearAnimation *nuclear;
+
+  nuclear = g_object_new (GTK_TYPE_NUCLEAR_ANIMATION, NULL);
+
+  nuclear->draw_background = draw_background;
+
+  return GDK_PAINTABLE (nuclear);
 }
 
 GtkWidget *
@@ -195,7 +204,7 @@ do_paintable_animated (GtkWidget *do_widget)
       gtk_window_set_default_size (GTK_WINDOW (window), 300, 200);
       g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
 
-      nuclear = gtk_nuclear_animation_new ();
+      nuclear = gtk_nuclear_animation_new (TRUE);
       image = gtk_image_new_from_paintable (nuclear);
       gtk_window_set_child (GTK_WINDOW (window), image);
       g_object_unref (nuclear);
index 022c156d8a23b36f21ce7d2692fd0b60523c682d..6374087b9691804c36a30178a1bf59fac2743315 100644 (file)
@@ -74,7 +74,8 @@ gtk_nuclear_media_stream_snapshot (GdkPaintable *paintable,
   /* We call the function from the previous example here. */
   gtk_nuclear_snapshot (snapshot,
                         width, height,
-                        2 * G_PI * nuclear->progress / DURATION);
+                        2 * G_PI * nuclear->progress / DURATION,
+                        TRUE);
 }
 
 static GdkPaintable *
index 4cd2ab9116a842a9643456a88e381c87b77d9e2e..a91aa6c2271d0ee986fc6af633a78106312113bc 100644 (file)
@@ -437,7 +437,7 @@ do_sliding_puzzle (GtkWidget *do_widget)
       choices = gtk_flow_box_new ();
       gtk_widget_add_css_class (choices, "view");
       add_choice (choices, puzzle);
-      add_choice (choices, gtk_nuclear_animation_new ());
+      add_choice (choices, gtk_nuclear_animation_new (TRUE));
       media = gtk_media_file_new_for_resource ("/images/gtk-logo.webm");
       gtk_media_stream_set_loop (media, TRUE);
       gtk_media_stream_set_muted (media, TRUE);
index ffb0edd3182a3c9f8d49ece3aa39fc3969cd0354..42c0f6636fe892e05d2d6a8e14fb89672bd458b6 100644 (file)
@@ -142,7 +142,7 @@ insert_text (GtkTextView *view)
                                      32, 1,
                                      gtk_widget_get_direction (widget),
                                      0);
-  nuclear = gtk_nuclear_animation_new ();
+  nuclear = gtk_nuclear_animation_new (TRUE);
 
   /* get start of buffer; each insertion will revalidate the
    * iterator to point to just after the inserted text.